/*
 *  thread_test.cpp
 */

#include <iostream>
#include "thread.h"
#include "thread_exception.h"
#include "mutex.h"
#include "charprinter.h"

int main(int argc, char* argv[])
{
    char* buf = "abcdefghijklmnopqrstuvwxyz0123456789\
abcdefghijklmnopqrstuvwxyz0123456789\
abcdefghijklmnopqrstuvwxyz0123456789\
abcdefghijklmnopqrstuvwxyz0123456789\
abcdefghijklmnopqrstuvwxyz0123456789\
abcdefghijklmnopqrstuvwxyz0123456789\
abcdefghijklmnopqrstuvwxyz0123456789\
abcdefghijklmnopqrstuvwxyz0123456789\
abcdefghijklmnopqrstuvwxyz0123456789\
abcdefghijklmnopqrstuvwxyz0123456789\
abcdefghijklmnopqrstuvwxyz0123456789\
abcdefghijklmnopqrstuvwxyz0123456789\
abcdefghijklmnopqrstuvwxyz0123456789\
abcdefghijklmnopqrstuvwxyz0123456789\
abcdefghijklmnopqrstuvwxyz0123456789\
abcdefghijklmnopqrstuvwxyz0123456789\
abcdefghijklmnopqrstuvwxyz0123456789\
abcdefghijklmnopqrstuvwxyz0123456789\
abcdefghijklmnopqrstuvwxyz0123456789\
abcdefghijklmnopqrstuvwxyz0123456789\
abcdefghijklmnopqrstuvwxyz0123456789\
abcdefghijklmnopqrstuvwxyz0123456789\
abcdefghijklmnopqrstuvwxyz0123456789\
abcdefghijklmnopqrstuvwxyz0123456789\
abcdefghijklmnopqrstuvwxyz0123456789\
abcdefghijklmnopqrstuvwxyz0123456789\
abcdefghijklmnopqrstuvwxyz0123456789\
abcdefghijklmnopqrstuvwxyz0123456789\
abcdefghijklmnopqrstuvwxyz0123456789\
abcdefghijklmnopqrstuvwxyz0123456789\
abcdefghijklmnopqrstuvwxyz0123456789\
abcdefghijklmnopqrstuvwxyz0123456789\
abcdefghijklmnopqrstuvwxyz0123456789\
abcdefghijklmnopqrstuvwxyz0123456789\
abcdefghijklmnopqrstuvwxyz0123456789\
abcdefghijklmnopqrstuvwxyz0123456789\
abcdefghijklmnopqrstuvwxyz0123456789\
abcdefghijklmnopqrstuvwxyz0123456789\
abcdefghijklmnopqrstuvwxyz0123456789\
abcdefghijklmnopqrstuvwxyz0123456789\
abcdefghijklmnopqrstuvwxyz0123456789\
abcdefghijklmnopqrstuvwxyz0123456789";

    int current_index = 0;

    Mutex mutex;

    CharPrinter cp1(1, buf, &current_index, &mutex);
    CharPrinter cp2(2, buf, &current_index, &mutex);
    
    Thread t1(cp1);
    Thread t2(cp2);
    
    try {
        t1.start();
        t2.start();

        t1.join();
        t2.join();
    } catch(ThreadException& e) {
        std::cout << e.what() << std::endl;
    } catch(...) {
        std::cout << "Unknown" << std::endl;
    }

    return 0;
}

//{+}

